﻿using FEM.Result;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PBSD_Development
{
    /// <summary>
    /// 体系对象
    /// </summary>
    public class SystemObj
    {
        /// <summary>
        /// 所有塔楼
        /// </summary>
        private TowerSet towerSet { set; get; }

        /// <summary>
        /// 塔楼列表
        /// </summary>
        private List<TowerObj> towerList { set; get; }

        /// <summary>
        /// 获得体系第一塔楼
        /// </summary>
        /// <returns> 塔楼对象 </returns>
        public TowerObj GetFirstTower()
        {
            return this.towerList.First();
        }

        /// <summary>
        /// 获得所有塔楼
        /// </summary>
        /// <returns> 塔楼对象列表 </returns>
        public List<TowerObj> GetTowerList()
        {
            return this.towerList;
        }

        /// <summary>
        /// 体系内塔楼查询
        /// </summary>
        /// <param name="towerIndex"> 塔楼编号 </param>
        /// <param name="towerObj"> 塔楼对象 </param>
        /// <returns> 是否存在 </returns>
        public bool GetTower(int towerIndex, out TowerObj towerObj)
        {
            //初始化
            towerObj = new TowerObj();
            //遍历楼层
            foreach (var tower in this.towerList)
            {
                if (tower.TowerIndex == towerIndex)
                {
                    towerObj = tower;
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 获得楼层
        /// </summary>
        /// <param name="storeyObj"></param>
        /// <returns></returns>
        public bool GetStorey(int towerIndex, int storeyIndex, out StoreyObj storeyObj)
        {
            //初始化
            TowerObj towerObj;
            storeyObj = new StoreyObj();
            //获得塔楼
            if (!this.GetTower(towerIndex, out towerObj)) return false;
            //获得楼层
            return towerObj.GetStorey(storeyIndex, out storeyObj);
        }

        /// <summary>
        /// 塔楼总数
        /// </summary>
        public int TowerCount
        {
            get
            {
                return this.towerSet.Count;
            }
        }

        /// <summary>
        /// 构造体系
        /// </summary>
        /// <param name="result"></param>
        public SystemObj(FEMResult result)
        {
            //初始化
            this.towerList = new List<TowerObj>();
            //获得塔楼
            this.towerSet = result.Towers;
            //遍历塔楼
            foreach (var tower in this.towerSet.Towers)
            {
                this.towerList.Add(new TowerObj(tower, result));
            }
        }
    }
}
